/**
 * Created by PengWei on 2018/7/26.
 */

namespace mengdao {
    /**
     * 生命周期
     */
    export class Lifecycle {//ask 建议抽象出接口，实现都通过内置这个类的实例来实现
        /** 生命周期当前状态 */
        private _state: LifecycleState = LifecycleState.NEW;//ask 这里提供的值是string

        /** 生命周期类型 */
        private _type: LifecycleType;

        /**
         * 设置生命周期状态
         * @param state
         */
        public set state(state: LifecycleState) {
            this._state = state;
        }

        public get state(): LifecycleState {
            return this._state;
        }

        /**
         * 设置生命周期类型
         * @param type
         */
        public set type(type: LifecycleType) {
            this._type = type;
        }

        public get type(): LifecycleType {
            return this._type;
        }

        /**
         * 是否已经初始化过
         */
        public get hasInitialized(): boolean {
            return this._state != LifecycleState.NEW;
        }

        /**
         * 是否激活中
         */
        public get isActive(): boolean {
            return this._state == LifecycleState.ACTIVE;
        }

        /**
         * 是否中断中
         */
        public get isSuspend(): boolean {
            return this._state == LifecycleState.SUSPEND;
        }

        /**
         * 是否已销毁
         */
        public get hasDestroyed(): boolean {
            return this._state == LifecycleState.DESTROY;
        }
    }
}